package com.xyhuo.leetcode.november;

/**
 * 盛最多水的容器
 * https://leetcode.cn/problems/container-with-most-water/
 *
 * @time 2023/11/30
 */
public class MaxArea {

//    public static void main(String[] args) {
//        MaxArea maxArea = new MaxArea();
//        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
//        int i = maxArea.maxArea(height);
//        System.out.println(i);
//    }

    public int maxArea(int[] height) {
        int len = height.length;
        int left = 0, right = len - 1;
        int ans = 0;
        while (true) {
            if (left >= right) {
                break;
            }
            int tmp = (right - left) * Math.min(height[left], height[right]);
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
            if (tmp > ans) {
                ans = tmp;
            }
        }
        return ans;
    }
}
